<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script src="./node_modules/vue/dist/vue.js"></script>

<body>
    <div id='app'>
        <p v-upper-text='msg'>uuu</p>
        自动获取焦点：<input type="text" v-focus>
    </div>
</body>
<script>
    // 自定义一个组件
    Vue.directive('upper-text', {
        //设置样式在bind中
        bind: function (el) {
            el.style.color = 'red'
        },
        //js方法写在inserted中
        inserted: function (el, binding) {
            //将所有字母文本内容转换为大写
            el.innerHTML = binding.value.toUpperCase()
        }
    })

    new Vue({
        el: '#app',
        data: {
            msg: 'hahah,你好啊'
        },
        // 注册自定义组件 局部指令
        directives: {
            'focus': {
                //刷新页面自动获取焦点
                inserted: function (el, binding) {
                    el.focus()
                }
            }
        }
    })
</script>

</html>